# value = 1.2345
# print(format(value, '0.2f'))
# print(format(value, '0.3f'))
# print(format(value, '10.4f'))
# print(f"value is {value:10.4f}")
# print(f"value is {value:.2f}"
# print(f"value is {value:<10.4f}")
# print(f"value is {value:>10.4f}")
# print(f"value is {value:^10.4f}")
# a, b = 2.3, 4.5
# c = a + b
# print((a + b) == 6.8)
# 原有的精度已经在新版本的python中得到解决，deciaml模块用于金融领域，了解就好
# a = 1234.123
# print(f"{a:.2f}")
# print(f"{a:.2e}")
# print(f"{a:e}")
# a = 123140777390570321953190751375105749573098512353
# nbyt, rem = divmod(a.bit_length(), 8)
# abyt = a.to_bytes(nbyt + (1 if rem else 0), "little")
# print(abyt)
# 复数的加减乘除sin cos exp都通过cmath执行，标准的math不包含 numpy支持复数操作
# a = 5 / 4
# b = 7 / 16
# print(a * b)
# # fractions可以执行分数数学运算
# from fractions import Fraction
#
# c = Fraction(5, 4)
# d = Fraction(7, 16)
# print(c * d)
# import numpy as np
#
# ax = np.array([[1, 2, 3], [4, 5, 6]])
# bx = np.array([[1, 2], [3, 4], [5, 6]])
# print(ax @ bx)

# random模块 random.choice()用于从一个序列中选择一个元素
# random.sample()用于从一个序列中选择多个元素
# random.shuffle()用于将序列中的元素打乱 需要时再找
# from datetime import datetime, timedelta
#
# weekdays = ['Monday', 'Tuesday', 'Wednesday', 'Thursday',
#             'Friday', 'Saturday', 'Sunday']
#
#
# def get_previous_byday(dayname, start_date=None):
#     if start_date is None:
#         start_date = datetime.today()
#     day_num = start_date.weekday()
#     day_num_target = weekdays.index(dayname)
#     days_ago = (7 + day_num - day_num_target) % 7
#     if days_ago == 0:
#         days_ago = 7
#     target_date = start_date - timedelta(days=days_ago)
#     return target_date
#
#
# day = get_previous_byday('Monday')
# print(day)
# from datetime import datetime, date, timedelta

# import calendar
#
#
# def get_month_range(start_date=None):
#     if start_date is None:
#         start_date = date.today().replace(day=1)
#     _, days_in_month = calendar.monthrange(start_date.year, start_date.month)
#     end_date = start_date + timedelta(days=days_in_month)
#     return (start_date, end_date)
# print(datetime.now())
# text = '2012-09-20'
# x = datetime.strptime(text, '%Y-%m-%d')
# y = datetime.now()
# z = y - x
# print(z)
